package http

import (
	"github.com/gin-gonic/gin"
	"wzgames/pkg/server/http/types"
)

type HttpOption func(*gin.Engine)

func Use(mids ...gin.HandlerFunc) HttpOption {
	return func(o *gin.Engine) {
		for _, mid := range mids {
			o.Use(mid)
		}
	}
}

func Route(cb func(g *gin.Engine)) HttpOption {
	return func(o *gin.Engine) {
		cb(o)
	}
}

func MethodMapper(group *gin.RouterGroup, method types.Method) func(relativePath string, handlers ...gin.HandlerFunc) gin.IRoutes {
	if method == types.GET {
		return group.GET
	}
	if method == types.POST {
		return group.POST
	}
	if method == types.DELETE {
		return group.DELETE
	}
	if method == types.PUT {
		return group.PUT
	}
	return group.Any
}
